/**
 * @file main.cpp
 * @author Derek Liu (yjkhtddx@sina.com)
 * @brief 
 * @version 0.1
 * @date 2020-09-21
 * 
 * @copyright Copyright Sci-Tech Laboratories (c) 2020
 * 
 */

#include <iostream>
#include <unistd.h>
#include "RtspStreamManager.h"
#include "HLSRecord.h"

int main(int argc, char **argv)
{
    std::string recordPath = "/opt/data/RtspRecordHLS/record/";
    // std::string rtspUrl = "rtsp://admin:julong123@192.168.1.103:554/cam/realmonitor?channel=1&subtype=0";
    std::string rtspUrl = "rtsp://admin:julong123@192.168.1.80:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1";

    GBXUEAN::HLSRecord::Option option;
    option.prefix = "/opt/data/RtspRecordHLS/record/";
    option.streamId = 1;
    GBXUEAN::HLSRecord *record = new GBXUEAN::HLSRecord(option);
    RtspStreamManager::getInstance()->configurationinfo();
    RtspStreamManager::getInstance()->setFmtCtxCallback([record](uint32_t streamId, const AVFormatContext *ifmtCtx) {
        record->start(ifmtCtx);
    });
    RtspStreamManager::getInstance()->setPacketCallback([record](uint32_t streamId, AVPacket *packet) {
        record->onPacket(packet);
    });
    RtspStreamManager::getInstance()->openStream(rtspUrl);

    while (1)
    {
        printf("...\n");
        sleep(1);
    }
    std::cout << "Hello World!" << std::endl;
    return 0;
}